package com.yxzx.ebs.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yxzx.ebs.entity.EbsTeacher;
import com.yxzx.ebs.entity.vo.TeacherQuery;
import com.yxzx.ebs.mapper.EbsTeacherMapper;
import com.yxzx.ebs.service.EbsTeacherService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 讲师 服务实现类
 * </p>
 *
 * @author kongfuzi
 * @since 2020-07-22
 */
@Service
public class EbsTeacherServiceImpl extends ServiceImpl<EbsTeacherMapper, EbsTeacher> implements EbsTeacherService {

    /**
     * 根据多个条件查询讲师列表
     * @param page
     * @param teacherQuery
     */
    @Override
    public void pageQuery(Page<EbsTeacher> page, TeacherQuery teacherQuery) {
        QueryWrapper<EbsTeacher> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByAsc("sort");

        if (teacherQuery == null){
            baseMapper.selectPage(page,queryWrapper);
            return;
        }

        String name = teacherQuery.getName();
        String level = teacherQuery.getLevel();
        String begin = teacherQuery.getBegin();
        String end = teacherQuery.getEnd();

        if (!StringUtils.isEmpty(name)){
            queryWrapper.like("name",name);
        }
        if(!StringUtils.isEmpty(level)){
            queryWrapper.eq("level",level);
        }
        if(!StringUtils.isEmpty(begin)){
            queryWrapper.gt("gmt_create",begin);
        }
        if(!StringUtils.isEmpty(end)){
            queryWrapper.lt("gmt_create",end);
        }
        baseMapper.selectPage(page,queryWrapper);
    }
}
